<% page_title "Builds" %>

<%= render 'projects/header', project: @project, tab: "builds" if @project %>

<section class="tabs">
  <div class="row">
    <%= search_form do %>
      <%= search_select :external, [["Yes", "true"], ["No", "false"]], size: 1 %>
      <%= search_select :time_format, User::TIME_FORMATS, selected: params.dig(:search, :time_format) || current_user.time_format, label: 'Time', size: 1 %>
    <% end %>
  </div>

  <p class="pull-right">
    <% if @project && !@project.docker_image_building_disabled? %>
      <%= link_to "Edit Pre Build Command", project_build_command_path(@project), class: "btn btn-default"  %>
      <%= link_to "New", new_project_build_path(@project), class: "btn btn-default" %>
    <% end %>
  </p>

  <table class="table">
    <thead>
    <tr>
      <th>Name</th>
      <% if @project %>
        <th>Deployed to</th>
      <% else %>
        <th>Project</th>
      <% end %>
      <th>Created</th>
      <th>
        Duration
        <%= link_to_chart "Build duration", @builds.map(&:duration).compact %>
      </th>
      <th>Git Ref</th>
      <th></th>
      <th>Status</th>
    </tr>
    </thead>

    <tbody>
    <%= render partial: "builds/build", collection: @builds, as: :build %>
    </tbody>
  </table>

  <%= paginate @builds %>
</section>
